package com.online.servlet.user;

import com.online.dao.user.Impl.ShopDaoImpl;
import com.online.dao.user.ShopDao;
import com.online.pojo.User;
import com.online.service.user.Impl.ShopServiceImpl;
import com.online.service.user.Impl.UserServiceImpl;
import com.online.service.user.ShopService;
import com.online.service.user.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ToShopServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String shop_n=req.getParameter("shop_n");
        String legal_pn=req.getParameter("legal_pn");
        String user_n=req.getParameter("user_n");
        String user_p=req.getParameter("user_p");
        String user_tel=req.getParameter("user_tel");
        UserService userService= new UserServiceImpl();
        User user= userService.login(user_n);
        System.out.println(user_tel+user_n+user_p);
        if (user.getUser_name()==null){
            System.out.println("账号为空");

        }
        if (user.getUser_number().equals(user_tel)&&user.getUser_pwd().equals(user_p)){
            System.out.println("登录成功");
            ShopService shopService = new ShopServiceImpl();
            boolean falg = shopService.approval(shop_n,legal_pn,user_n,user_p,user_tel);
            if (falg){
                System.out.println("审批提交成功！请等待管理员审批！");
                req.setAttribute("user",user.getUser_name());
                req.getRequestDispatcher("/jsp/orderpage.jsp").forward(req,resp);
            }
        }else {
            System.out.println("手机号或密码错误,找回密码！");
        }

    }
}
